package com.onepower.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onepower.core.domain.response.MatchProjectScoreInfo;
import com.onepower.core.modules.repository.entity.MatchProjectScore;
import com.onepower.core.modules.service.IMatchProjectScoreService;
import com.onepower.core.result.CommonResult;
import com.onepower.core.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kin
 * @since 2018-08-24
 */
@RestController
@RequestMapping("/api/match/projectScore")
public class MatchProjectScoreController {

    @Autowired
    private IMatchProjectScoreService matchProjectScoreService;

    @RequestMapping(value = "list", method = RequestMethod.GET)
    public CommonResult list(@RequestParam(value = "matchScheduleId", required = false, defaultValue = "-1") int matchScheduleId,
                             @RequestParam(value = "referee", required = false, defaultValue = "") String referee,
                             @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "20") int pageSize) {
        Page<MatchProjectScoreInfo> list = matchProjectScoreService.getList(new Page<>(pageNum, pageSize), matchScheduleId, referee);
        return ResultUtils.ok(list);
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    public CommonResult save(@RequestBody List<MatchProjectScore> matchProjectScoreList) {
        matchProjectScoreService.saveProjectScore(matchProjectScoreList);
        return ResultUtils.ok();
    }

    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public CommonResult delete(@RequestBody Integer[] ids) {
        matchProjectScoreService.removeByIds(Arrays.asList(ids));
        return ResultUtils.ok();
    }
}
